<template>
  <div>
    <!--1视图-->
    <el-form :inline="true" :model="user" class="demo-form-inline">
      <el-form-item label="用户名">
        <el-input v-model="user.username" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item label="公司名">
        <el-input v-model="user.company" placeholder="公司名"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="user.tel" placeholder="手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="id"
          label="编号"
          width="150">
      </el-table-column>
      <el-table-column
          prop="username"
          label="用户英文名"
          width="120">
      </el-table-column>
      <el-table-column
          prop="cname"
          label="用户中文名"
          width="120">
      </el-table-column>
      <el-table-column
          prop="tel"
          label="手机号"
          width="120">
      </el-table-column>
      <el-table-column
          prop="job"
          label="职位"
          width="100">
      </el-table-column>
      <el-table-column
          prop="company"
          label="公司中文名"
          width="150">
      </el-table-column>
      <el-table-column
          prop="ecompany"
          label="公司英文名"
          width="200">
      </el-table-column>
      <el-table-column
          prop="address"
          label="公司地址"
          width="200">
      </el-table-column>
      <el-table-column
          prop="email"
          label="邮箱"
          width="120">
      </el-table-column>
      <el-table-column
          prop="zb"
          label="坐标"
          width="120">
      </el-table-column>
      <el-table-column
          prop="indate"
          label="创建时间"
          width="120">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="del(scope.row.id)" type="text" size="small">逻辑删除</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        @current-change="goPage"
        :page-size="5"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>

  </div>

</template>

<script>
export default {
  name: "ListView",
  data() {
    return {
      //2属性定义
      tableData:[],
      user:{},
      total:0,
      pageNum:1
    }
  }, methods: {
    //3自定义方法
    del(id){
      this.axios.post("user/del?id="+id).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          this.list();
        }else {
          this.$message.error(res.data.msg);
        }
      })
    },
    goPage(page){
      this.pageNum=page;
      this.list();
    },
    list(){
      this.axios.post("user/list?pageNum="+this.pageNum,this.user).then(res=>{
        this.tableData=res.data.data.list;
        this.total=res.data.data.total;
      })
    }
  }, created() {
    //4.钩子函数
    this.list();
  }
}
</script>

<style scoped>

</style>